<?php

namespace App\Http\Requests\Admin\Store;

use App\Http\Requests\ApiRequest;
use App\Models\Admin\StoreAdmin;
use App\Models\Panx\Sex;
use App\Services\Locale\Language;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

/**
 * @property string name
 * @property string account
 * @property string password
 * @property string email
 * @property string phone
 * @property int sex
 * @property string born_at
 * @property string role_name
 */

class StaffStoreRequest extends ApiRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $data = [
            'name'      => 'required|string|max:'.self::MAX_STRING,
            'email'     => 'required|string|email|unique:store_admins,email|max:'.self::MAX_STRING,
            'account'   => ['required', 'string', 'max:'.self::MAX_STRING, Rule::unique((new StoreAdmin)->getTable(), 'account')],
            'password'  => 'required|string|min:6|max:'.self::MAX_STRING,
            'sex'       => ['required', 'int', Rule::in(Sex::allIds())],
            'born_at'   => 'nullable|date',
            'role_name' => 'required|string|max:'.self::MAX_STRING,
            'phone'     => ['required', 'string', 'max:'.self::MAX_STRING],
        ];

//        if (app()->getLocale() === Language::ZH_CN) {
//            $data['phone'] = ['required', 'regex:/^1[34578][0-9]{9}$|^((0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/'];
//        } else {
//            $data['phone'] = ['required', 'string'];
//        }

        return $data;
    }

    /**
     * @return array
     */
//    public function messages()
//    {
//        return [
//            'name.*'      => '名称必须填写',
//            'email.*'     => '邮箱必须是合法的',
//            'account.*'   => '账号已注册，请尝试其他账号',
//            'password.*'  => '密码长度必须6个字符',
//            'phone.*'     => '电话必须是合法手机号或座机号',
//            'sex.*'       => '性别必须是男和女',
//            'born_at.*'   => '出生日期必须是合法的日期',
//            'role_name.*' => '角色必须是字符串',
//        ];
//    }
}
